package com.jyniubi.gmall.payment.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jyniubi.gmall.oms.entity.OrderEntity;
import com.jyniubi.gmall.payment.mapper.PaymentInfoMapper;
import com.jyniubi.gmall.payment.service.PaymentService;
import com.jyniubi.gmall.payment.vo.PayVo;
import com.jyniubi.gmall.payment.vo.PaymentInfoEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Date;

@Service
public class PaymentServiceImpl implements PaymentService {
    @Autowired
    private PaymentInfoMapper paymentInfoMapper;
    @Override
    public Long savePayInfo(OrderEntity orderEntity,Integer payType) {
        PaymentInfoEntity paymentInfoEntity = new PaymentInfoEntity();
        paymentInfoEntity.setOutTradeNo(orderEntity.getOrderSn());
        paymentInfoEntity.setPaymentType(1);
        paymentInfoEntity.setTotalAmount(new BigDecimal("0.01"));
        paymentInfoEntity.setSubject("支付平台");
        paymentInfoEntity.setPaymentStatus(0);
        paymentInfoEntity.setCreateTime(new Date());
        this.paymentInfoMapper.insert(paymentInfoEntity);
        return paymentInfoEntity.getId();
    }

    @Override
    public PaymentInfoEntity queryPaymentInfoById(String payId) {
        PaymentInfoEntity paymentInfoEntity = this.paymentInfoMapper.selectById(payId);
        return paymentInfoEntity;
    }

    @Override
    public int updatePaymentInfo(PaymentInfoEntity paymentInfoEntity) {
        int update = this.paymentInfoMapper.updateById(paymentInfoEntity);
        return update;
    }
}
